package P3.T01;

import java.util.Iterator;

public class Fibo implements Iterable<Integer> {
	private int num;
	int pre=1,f=1;
	public Fibo(int num) {
		this.num=num;
	}
	@Override
	public Iterator<Integer> iterator() {
		return new FiboIterator();
	}
	private class FiboIterator implements Iterator<Integer>{
		private int cur=0;
		@Override
		public boolean hasNext() {
			return cur<num;
		}

		@Override
		public Integer next() {
			cur++;
			if(cur>2){
				int old=f;
				f=pre+f;
				pre=old;
			}
			return f;
		}
		
	}
}
